# oriental copper
import time
import parsel
# import common.dataBase as db
import requests
import urllib3

urllib3.disable_warnings()


def get_data(url):
    response = requests.get(url, verify=False)
    selectors = parsel.Selector(response.text)
    price = selectors.css(
        '#rightpanel div.mflink table table table.text_table tr:nth-child(2) td:nth-child(2) div::text').get()
    price = price.replace(',', '')
    date = selectors.css(
        '#rightpanel div.mflink table table table.text_table tr:nth-child(2) td:nth-child(1) div::text').get()
    return date, price


def app():
    url = 'https://www.orientalcopper.com/price.php'
    d = get_data(url)
    print(d)
    name = 'oriental copper'
    price = d[1]
    price_range = ''
    # today = time.strftime('%Y-%m-%d', time.localtime())
    today = d[0]
    insert_sql = f'INSERT INTO mat_price VALUES (null, "{name}", "{price}","{price_range}", "{today}", "{url}")'
    # db.save([insert_sql])
    print(insert_sql)


if __name__ == "__main__":
    app()
